package com.starry.home.ui.mine

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View.VISIBLE
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.drake.brv.utils.linear
import com.drake.brv.utils.setup
import com.google.android.material.imageview.ShapeableImageView
import com.starry.core.base.BaseActivity
import com.starry.core.ext.singleClick
import com.starry.core.utils.GlideUtils
import com.starry.home.R
import com.starry.home.databinding.ActivityMyDoctorBinding
import com.starry.home.logic.model.hospital.DoctorInfoBean
import com.starry.home.ui.hospital.DoctorActivity
import com.starry.home.viewmodel.mine.MyDoctorViewModel


/**
 * Package:com.starry.home.ui.mine
 * Author:starr
 * Time:2024/4/29 11:02
 * Description: 我的医生界面
 */
class MyDoctorActivity : BaseActivity<ActivityMyDoctorBinding, MyDoctorViewModel>() {

    private lateinit var doctorInfo: DoctorInfoBean
    override fun initData() {

    }

    @RequiresApi(Build.VERSION_CODES.O)
    override fun initView() {

        mDataBinding.titleTopBar.baseTvTitle.text = "我的医生"
        mDataBinding.titleTopBar.baseIvBack.setOnClickListener {
            finish()
        }
        mDataBinding.titleTopBar.baseIvBack.visibility = VISIBLE

        doctorInfo = DoctorInfoBean(
            1,
            DoctorInfoBean.EmrYsInfo(
                emrYsId = 7,
                emrYsName = "秦明",
                emrYsSection = "呼吸内科",
                emrYsTitle = "主任医师",
                emrYsPhone = "15116397582",
                emrYsImg = "https://starrylixu.oss-cn-beijing.aliyuncs.com/picgo/202401291613784.png",
            ), "msg"
        )

        mDataBinding.rvMyDoctor.linear().setup {
            addType<DoctorInfoBean>(R.layout.item_my_doctor)
            onBind {
                val model = getModel<DoctorInfoBean>()
                val ivUser = findView<ShapeableImageView>(R.id.ivUser)
                val tvRegister = findView<TextView>(R.id.tvRegister)
                val tvContact = findView<TextView>(R.id.tvContact)
                GlideUtils.loadImage(context, model.emrYsInfo.emrYsImg, ivUser)
                tvRegister.singleClick {
                    val bundle = Bundle()
                    bundle.putInt("ysId", model.emrYsInfo.emrYsId)
                    DoctorActivity.startAction(context, bundle)
                }

                tvContact.singleClick {
                    // 联系医生
                    val intent = Intent()
                    intent.action = Intent.ACTION_DIAL
                    intent.setData(Uri.parse("tel:" + model.emrYsInfo.emrYsPhone))
                    startActivity(intent)
                }
            }
        }.models = mutableListOf(doctorInfo)
    }

    override fun getLayoutId() = R.layout.activity_my_doctor

    companion object {
        fun startAction(mContext: Context) {
            val intent = Intent(mContext, MyDoctorActivity::class.java)
            mContext.startActivity(intent)
        }
    }
}